package com.cloudoer.blog.service.impl;

import com.cloudoer.blog.annotation.AddIdAnnotation;
import com.cloudoer.blog.base.BaseService;
import com.cloudoer.blog.model.Tag;
import com.cloudoer.blog.service.TagService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service(value = "tagService")
public class TagServiceImpl extends BaseService implements TagService {
    @Override
    public Tag getById (String id){
        return tagDao.selectByPrimaryKey(id);
    }

    @Override
    @AddIdAnnotation
    public String add(Tag tag) {
        tag.setId(UUID.randomUUID().toString().replace("-", ""));
        tagDao.insertSelective(tag);
        return tag.getId();
    }

    @Override
    public int update(Tag tag) {
        return tagDao.updateByPrimaryKeySelective(tag);
    }

    @Override
    public int delete(String id) {
        return tagDao.deleteByPrimaryKey(id);
    }

    @Override
    public List<Tag> getAll() {
        return tagDao.selectAll();
    }

    @Override
    public List<Tag> getByPage(int pstart, int psize) {
        return tagDao.selectByPage(pstart, psize);
    }

    @Override
    public int getCount() {
        return tagDao.selectCount();
    }
}
